#include "rgsmaptoolidentifyaction.h"

Rgsmaptoolidentifyaction::Rgsmaptoolidentifyaction(QgsMapCanvas *canvas)
    :QgsMapToolIdentify(canvas)
{

    mSelectionHandler = new RgsMapToolSelectionHandler( canvas, RgsMapToolSelectionHandler::SelectSimple );
    connect( mSelectionHandler, &RgsMapToolSelectionHandler::geometryChanged, this, &Rgsmaptoolidentifyaction::identifyFromGeometry );
}

Rgsmaptoolidentifyaction::~Rgsmaptoolidentifyaction()
{
    delete mSelectionHandler;
}

void Rgsmaptoolidentifyaction::canvasMoveEvent(QgsMapMouseEvent *e)
{
    mSelectionHandler->canvasMoveEvent(e);
}

void Rgsmaptoolidentifyaction::canvasPressEvent(QgsMapMouseEvent *e)
{
    mSelectionHandler->canvasPressEvent(e);
}

void Rgsmaptoolidentifyaction::canvasReleaseEvent(QgsMapMouseEvent *e)
{
    mSelectionHandler->canvasReleaseEvent(e);
}

void Rgsmaptoolidentifyaction::identifyFromGeometry()
{
    const QgsGeometry geometry = mSelectionHandler->selectedGeometry();
    //const bool isSinglePoint = geometry.type() == QgsWkbTypes::PointGeometry;
    QgsIdentifyContext identifyContext;
    IdentifyMode mode =  ActiveLayer ;
    QList<QgsMapLayer *> layerList;
    layerList = Riskgis::instance()->GetLayerTreeView()->selectedLayersRecursive();
    const QList<IdentifyResult> results = QgsMapToolIdentify::identify( geometry, mode, layerList, AllLayers, identifyContext );

    qDebug()<<"选择的图层数量："<<layerList.size();
    qDebug()<<"选择的要素数量："<<layerList.size();

    if ( results.isEmpty() )
    {
        //resultsDialog()->clear();
        //QgisApp::instance()->statusBarIface()->showMessage( tr( "No features found at this position." ), 2000 );
    }
    else
    {
//        // Show the dialog before items are inserted so that items can resize themselves
//        // according to dialog size also the first time, see also #9377
//        if ( results.size() != 1 || !QgsSettings().value( QStringLiteral( "/Map/identifyAutoFeatureForm" ), false ).toBool() )
//            //resultsDialog()->QDialog::show();

        QList<IdentifyResult>::const_iterator result;
        for ( result = results.constBegin(); result != results.constEnd(); ++result )
        {
            //resultsDialog()->addFeature( *result );
            qDebug()<<result->mFeature.id();
        }


    }



}
